package dataObject;

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;

import controller.IOPrinter;

public class Product {
	private String name;
	private Discount discount;
	private Date releaseDate;
	private int price;
	private double size;
	private int batterySize;
	private int cameraPixel;
	private int finalPrice;
	private int availableColor;
	public Product(String name,String releaseDate,double size,int price,int batterySize,int cameraPixel,int availableColor)
	{
		String[] date = releaseDate.split("-");
		this.name = name;
		this.releaseDate = new GregorianCalendar(Integer.parseInt(date[0]),Integer.parseInt(date[1])-1,Integer.parseInt(date[2])).getTime();
		this.price = price;
		this.size = size;
		this.batterySize = batterySize;
		this.cameraPixel = cameraPixel;
		this.availableColor = availableColor;
		setDiscountType();
		setFinalPrice();
	}
	public String getName()
	{
		return name;
	}
	public void printList()
	{
		IOPrinter printer = IOPrinter.getPrinter();
		printer.printProduct(name,price,finalPrice,size,cameraPixel,batterySize);
	}
	public int getOriginalPrice()
	{
		return price;
	}
	public int getFinalPrice()
	{
		return finalPrice;
	}
	public double getSize()
	{
		return size;
	}
	public int getBatterySize()
	{
		return batterySize;
	}
	public int getCameraPixel()
	{
		return cameraPixel;
	}
	public int getAvailableColor()
	{
		return availableColor;
	}
	private void setDiscountType()
	{
		long dateDifference = getToday();
		
		if(dateDifference>365)
			discount = new Gold();
		else if(dateDifference>180)
			discount = new Silver();
		else if(dateDifference>90)
			discount = new Bronze();
		else
			discount = new Normal();
	}
	public long getToday()
	{
		Date todayDate = new Date(System.currentTimeMillis()); 
		return getDatediff(todayDate);
	}
	private void setFinalPrice()
	{
		finalPrice = (int) (price * discount.getDiscount());
	}
	protected long getDatediff(Date todayDate)
	{
		long diffInMillies = todayDate.getTime() - releaseDate.getTime();
		return TimeUnit.MILLISECONDS.toDays(diffInMillies);
	}
}